package com.howdee.howdyags.settings;

import android.database.DataSetObserver;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.howdee.howdyags.actionbar.ActionBarActivity;
import com.howdee.howdyags.R;

public class SettingsActivity extends ActionBarActivity {

	private ListView mListView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

        setContentView(R.layout.settings);
        getActionBar().setIcon(R.drawable.ic_cab_done_holo_dark);
        getActionBar().setHomeButtonEnabled(true);
        
        mListView = (ListView)findViewById(R.id.lst_settings);
        mListView.setAdapter(new SettingsListAdapter());
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			finish();
			break;
		}
		return super.onOptionsItemSelected(item);
	}

	private class SettingsListAdapter implements ListAdapter {
		private static final int SETTING_COUNT = 2;

		public int getCount() {
			return SETTING_COUNT;
		}

		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return null;
		}

		public long getItemId(int position) {
			return position;
		}

		public int getItemViewType(int position) {
			return R.layout.setting_checkbox;
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			if(convertView==null) {
				convertView = getLayoutInflater().inflate(R.layout.setting_checkbox, null);
			}
			
			switch(position) {
			case 0:
				return getStartPageView(convertView);
			case 1:
				return getAutoScrollView(convertView);
			default:
				return null;
			}
		}

		private View getStartPageView(View convertView) {
			TextView txtSettingLabel = (TextView)convertView.findViewById(R.id.txt_setting_label);
			TextView txtSettingDtl = (TextView)convertView.findViewById(R.id.txt_setting_dtl);
			CheckBox checkBox = (CheckBox)convertView.findViewById(R.id.checkbox);
			
			txtSettingLabel.setText(getString(R.string.lbl_start_page));
			txtSettingDtl.setVisibility(View.VISIBLE);
			txtSettingDtl.setText(getString(R.string.lbl_start_page_dtl));
//			checkBox.setOnCheckedChangeListener(listener);
			
			return convertView;
		}

		private View getAutoScrollView(View convertView) {
			TextView txtSettingLabel = (TextView)convertView.findViewById(R.id.txt_setting_label);
			TextView txtSettingDtl = (TextView)convertView.findViewById(R.id.txt_setting_dtl);
			CheckBox checkBox = (CheckBox)convertView.findViewById(R.id.checkbox);
			
			txtSettingLabel.setText(getString(R.string.lbl_auto_scroll));
			txtSettingDtl.setVisibility(View.GONE);
			
			return convertView;
		}

		public int getViewTypeCount() {
			return 1;
		}

		public boolean hasStableIds() {
			return false;
		}

		public boolean isEmpty() {
			return false;
		}

		public void registerDataSetObserver(DataSetObserver observer) {
		}

		public void unregisterDataSetObserver(DataSetObserver observer) {
		}

		public boolean areAllItemsEnabled() {
			return true;
		}

		public boolean isEnabled(int position) {
			return true;
		}

	}
}
